<?php

namespace app\supplier\controller\supplier;

use app\common\model\european\EuropeanUserPicking;
use app\common\model\settings\Setting as SettingModel;
use app\common\model\user\Tag as TagModel;
use app\shop\model\user\Grade;
use app\shop\model\user\User as UserModel;
use app\supplier\model\supplier\DepositRefund as DepositRefundModel;
use app\supplier\model\supplier\Supplier as SupplierModel;
use app\supplier\controller\Controller;
/**
 * 供应商
 */
class Supplier extends Controller
{
    /**
     * 获取用户信息
     */
    public function getUserInfo()
    {
        $supplier = $this->supplier['supplier'];
        // 商城名称
        $shop_name = SettingModel::getItem('store')['name'];
        //当前系统版本
        $version = get_version();
        return $this->renderSuccess('', compact('supplier', 'shop_name', 'version'));
    }

    /**
     * 竞猜比分
     * guessingscorelist
     * \think\response\Json
     * @return \think\response\Json
     * @Author kevin
     * @date 2024/6/7 12:57
     */
    public function guessingscorelist()
    {

        $params = $this->postData();
        $params['shop_supplier_id'] = $this->getSupplierId();
        $list = EuropeanUserPicking::getList($params);
        return $this->renderSuccess('竞猜比分列表', compact('list'));
    }


    /**
     * 比分猜中发放优惠券
     * updateIsGive
     * @param $european_user_picking_id
     * \think\response\Json
     * @return \think\response\Json
     * @Author kevin
     * @date 2024/6/5 15:14
     */
    public function updateIsGive($european_user_picking_id = 0)
    {
        if(EuropeanUserPicking::where('european_user_picking_id',$european_user_picking_id) -> update(['is_give' => 1])){
            return $this->renderSuccess('操作成功');
        }else{
            return $this->renderError('操作失败');
        }
    }

    /**
     * 获取用户列表数据
     * getUserListData
     * @param $nickName
     * @param $gender
     * @param $reg_date
     * @param $grade_id
     * \think\response\Json
     * @return \think\response\Json
     * @Author kevin
     * @date 2024/5/9 17:31
     */
    public function getUserListData($nickName = '', $gender = null, $reg_date = '', $grade_id = null)
    {
        $list = UserModel::getList($nickName, $grade_id, $reg_date, $gender = -1, $this->postData());
        $GradeModel = new Grade();
        $grade = $GradeModel->getLists();
        // 所有标签
        $allTag = TagModel::getAll();
        return $this->renderSuccess('', compact('list', 'grade', 'allTag'));
    }

    public function export($nickName = '', $gender = null, $reg_date = '', $grade_id = null){

        $list = UserModel::getExportList($nickName, $grade_id, $reg_date, $gender = -1, $this->postData());
        $xls_cell = [
            ['user_id' , '用户ID'],
            ['nickName' , '昵称'],
            ['create_time' , '注册时间'],
        ];
        $exp_title = '邀请用户数据' . date('Y-m-d H:i:s');
        exportExcel($exp_title, $xls_cell, $list);
    }

    /**
     * 申请退押金
     */
    public function refund(){
        $supplier = SupplierModel::detail($this->getSupplierId());
        $model = new DepositRefundModel;
        if ($model->submit($supplier)) {
            return $this->renderSuccess('申请退款成功');
        }
        return $this->renderError($model->getError() ?: '提交失败');
    }

    /**
     * 商户列表
     */
    public function getUserList($nickName = '', $gender = null, $reg_date = '', $grade_id = null)
    {

        $params = $this->postData();
        $params['shop_supplier_id'] = $this->getSupplierId();
        $list = UserModel::getList($nickName, $grade_id, $reg_date, $gender = -1, $params);
        $GradeModel = new Grade();
        $grade = $GradeModel->getLists();
        // 所有标签
        $allTag = TagModel::getAll();
        return $this->renderSuccess('', compact('list', 'grade', 'allTag'));
    }
}
